package ltd.trackan.messagecenter.scheduled;

import lombok.extern.slf4j.Slf4j;
import ltd.trackan.messagecenter.email.MailController;
import ltd.trackan.messagecenter.send.SendController;
import ltd.trackan.messagecenter.service.JDAccountService;
import ltd.trackan.messagecenter.service.MessageChannelService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author wxa
 */
@Component
@Slf4j
public class ScheduledTasks {
    @Resource
    JDAccountService jdAccountService;
    @Resource
    MessageChannelService messageChannelService;
    @Resource
    MailController mailController;
    @Resource
    SendController sendController;

    // 每隔十分钟一次
    @Scheduled(fixedRate = 600000)
    public void reportCurrentTime() {
        log.info("---开始执行定时任务---");
        log.info("<<<开始更新JD账号与id映射信息>>>");
        jdAccountService.updateMapper();
        log.info(">>>完成更新JD账号与id映射信息<<<");
        log.info("<<<开始更新id的渠道信息>>>");
        messageChannelService.updateAllMessageChannel();
        log.info(">>>完成更新id的渠道信息<<<");
        log.info("<<<开始接收邮件>>>");
        mailController.receiveMail();
        log.info(">>>完成接收邮件<<<");
        log.info("<<<开始发送信息>>>");
        sendController.start();
        log.info(">>>完成发送信息<<<");
        log.info("---结束执行定时任务---");
    }
}
